<template>
    <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady" 
          style="height:100%" class='ag-theme-alpine'
          :defaultColDef="defaultColDef" :rowData="table.dataList" 
          :columnDefs="cfsValue" :localeText="localeTextData"/>
    <paginationCopys :total="total" show-total show-jumper 
        show-page-size @change="changePage"  @page-size-change="changeSize" 
        style="justify-content: center;margin-top: 10px;"  :page-size="pagination.pageSize"
        :current="pagination.page" />
</template>
<script lang="ts">

import { localeText } from '@/api/aggridZw'
import emitter from "@/hooks/useEventBus";
import { onMounted,reactive, ref } from 'vue';
import { usePagination, useTable } from '@/hooks/table';
import { verfiyShrinkReg } from '@/api/PhysicalSurveyRoom/physicalTestApi';
import { assTable } from '@/utils/assemblyLevelTable';
import { Message } from '@arco-design/web-vue';
export default {
    name:'shinkageTestApproved',
    components: {  },
    props:{ 
       searchData:{
          type:Object,
          default:() => {}
       }
    },
    setup(props,{emit}){
        const table = useTable();
        const pageData = reactive<{
            pageLoading:boolean,
        }>({ 
            pageLoading:false
        });
        const verfiyShrinkRegApi = verfiyShrinkReg();
        emitter.on("shinkageTestApproved", () => {
                pagination.page = 1;
                doRefresh();
            });
        const doRefresh = async () => {
            pageData.pageLoading = true;
             await verfiyShrinkRegApi.getPageVerfiyShrinkRegList({
                 page: pagination.page,
                 size: pagination.pageSize,
                 ...props.searchData,
                 auditState: 1
             }).then(({code,data}:any) => {
                 if (code === 200) {
                     table.handleSuccess(data.list);
                     gridOption.value.setRowData(data.list); 
                     total.value = data.total; 
                 }
             }).catch(console.log).finally(() => {
                 pageData.pageLoading = false;
             }); 
        };
        const pagination = usePagination(doRefresh);
        //表格方面
        const gridOption = ref();
        const gridReady = (params:any) => {
          gridOption.value = params.api; 
          //调整表格自适应大小
        }
        const defaultColDef = {
            sortable: true,
            resizable: true,
            filter: true,
            width: 150
        };
        let cfsValue:any = [
            {
                headerName: "序号",
                key: "serialNo",
                field: "serialNo",
            },
            {
                headerName: "开单日期",
                key: "billDate",
                field: "billDate",
            },
            {
                headerName: "记录单号",
                key: "verifyShrinkRegistCode",
                field: "verifyShrinkRegistCode",
            },
            {
                headerName: "流转卡号",
                key: "circulatCard",
                field: "circulatCard",
                slotName: "circulatCard",
            },
            {
                headerName: "客户",
                key: "customName",
                field: "customName",
                slotName: "customName",
            },
            {
                headerName: "布号",
                key: "clothCode",
                field: "clothCode",
                slotName: "clothCode",
            },
            {
                headerName: "品名",
                key: "brandName",
                field: "brandName",
                slotName: "brandName",
            },
            {
                headerName: "颜色深浅",
                key: "colorDepth",
                field: "colorDepth",
                slotName: "colorDepth",
            },
            {
                headerName: "色号",
                key: "colorCode",
                field: "colorCode",
                slotName: "colorCode",
            },
            {
                headerName: "色称",
                key: "colorName",
                field: "colorName",
                slotName: "colorName",
            },
            {
                headerName: "合约号",
                key: "contractNo",
                field: "contractNo",
                slotName: "contractNo",
            },
            {
                headerName: "客户订单号",
                key: "customOrderNo",
                field: "customOrderNo",
                slotName: "customOrderNo",
            },
            {
                headerName: "坯布批号",
                key: "greyBatch",
                field: "greyBatch",
                slotName: "greyBatch",
            },
            {
                headerName: "坯布名称",
                key: "greyName",
                field: "greyName",
                slotName: "greyName",
            },
            {
                headerName: "匹数",
                key: "pieceNum",
                field: "pieceNum",
                slotName: "pieceNum",
            },
            {
                headerName: "设备编号",
                key: "deviceCode",
                field: "deviceCode",
                slotName: "deviceCode",
            },
            {
                headerName: "定型机台",
                key: "shapMachine",
                field: "shapMachine",
                slotName: "shapMachine",
            },
            {
                headerName: "预缩",
                key: "preshrunk",
                field: "preshrunk",
                slotName: "preshrunk",
            },
            {
                headerName: "重量",
                key: "weight",
                field: "weight",
                slotName: "weight",
            },
            {
                headerName: "胚洗前",
                key: "embWashBefore",
                children: [
                    {
                        headerName: "克重",
                        field: "firstGreyWashWeight",
                        slotName: "firstGreyWashWeight",
    
                    },
                    {
                        headerName: "门幅",
                        field: "firstGreyWashWidth",
                        slotName: "firstGreyWashWidth",
    
                    },
                ]
            },
            {
                headerName: "胚洗后",
                key: "embWashAfter",
                children: [
                    {
                        headerName: "克重",
                        field: "afterGreyWashWeight",
                        slotName: "afterGreyWashWeight",
    
                    },
                    {
                        headerName: "门幅",
                        field: "afterGreyWashWidth",
                        slotName: "afterGreyWashWidth",
    
                    },
                ]
            },
            {
                headerName: "定前",
                key: "finalizeBefore",
                children: [
                    {
                        headerName: "克重",
                        field: "firstSetWeight",
                        slotName: "firstSetWeight",
    
                    },
                    {
                        headerName: "门幅",
                        field: "firstSetWidth",
                        slotName: "firstSetWidth",
    
                    },
                ]
            },
            {
                headerName: "还原",
                key: "reduction",
                children: [
                    {
                        headerName: "克重",
                        field: "reductionWeight",
                        slotName: "reductionWeight",
    
                    },
                    {
                        headerName: "门幅",
                        field: "reductionWidth",
                        slotName: "reductionWidth",
    
                    },
                ]
            },
            {
                headerName: "定后",
                key: "finalizeAfter",
                field: "finalizeAfter",
                children: [
                    {
                        headerName: "克重",
                        field: "afterSetWeight",
                        slotName: "afterSetWeight",
    
                    },
                    {
                        headerName: "门幅",
                        field: "afterSetWidth",
                        slotName: "afterSetWidth",
    
                    },
                ]
            },
            {
                headerName: "水洗尺寸变化率类型",
                key: "washSizeChangeRateType",
                field: "washSizeChangeRateType",
                slotName: "washSizeChangeRateType",
            },
            {
                headerName: "洗前横向(%)",
                key: "washHorizontalBefore",
                children: [
                    {
                        headerName: "1",
                        field: "firstWashTransverse1",
                        slotName: "firstWashTransverse1",
    
                    },
                    {
                        headerName: "2",
                        field: "firstWashTransverse2",
                        slotName: "firstWashTransverse2",
    
                    },
                    {
                        headerName: "3",
                        field: "firstWashTransverse3",
                        slotName: "firstWashTransverse3",
    
                    },
                    {
                        headerName: "平均值",
                        field: "firstWashTransverseAvg",
                        slotName: "firstWashTransverseAvg",
    
                    },
                ]
            },
            {
                headerName: "洗前直向(%)",
                key: "washStraightBefore",
                children: [
                    {
                        headerName: "1",
                        field: "firstWashStraight1",
                        slotName: "firstWashStraight1",
    
                    },
                    {
                        headerName: "2",
                        field: "firstWashStraight2",
                        slotName: "firstWashStraight2",
    
                    },
                    {
                        headerName: "3",
                        field: "firstWashStraight3",
                        slotName: "firstWashStraight3",
    
                    },
                    {
                        headerName: "平均值",
                        field: "firstWashStraightAvg",
                        slotName: "firstWashStraightAvg",
    
                    },
                ]
            },
            {
                headerName: "洗后横向(%)",
                key: "washHorizontalAfter",
                children: [
                    {
                        headerName: "1",
                        field: "afterWashTransverse1",
                        slotName: "afterWashTransverse1",
    
                    },
                    {
                        headerName: "2",
                        field: "afterWashTransverse2",
                        slotName: "afterWashTransverse2",
    
                    },
                    {
                        headerName: "3",
                        field: "afterWashTransverse3",
                        slotName: "afterWashTransverse3",
    
                    },
                    {
                        headerName: "平均值",
                        field: "afterWashTransverseAvg",
                        slotName: "afterWashTransverseAvg",
    
                    },
                ]
            },
            {
                headerName: "洗后直向%",
                key: "washStraightAfter",
                children: [
                    {
                        headerName: "1",
                        field: "afterWashStraight1",
                        slotName: "afterWashStraight1",
    
                    },
                    {
                        headerName: "2",
                        field: "afterWashStraight2",
                        slotName: "afterWashStraight2",
    
                    },
                    {
                        headerName: "3",
                        field: "afterWashStraight3",
                        slotName: "afterWashStraight3",
    
                    },
                    {
                        headerName: "平均值",
                        field: "afterWashStraightAvg",
                        slotName: "afterWashStraightAvg",
    
                    },
                ]
            },
            {
                headerName: "缩水率(挂干)",
                key: "shrinkageHangdry",
                children: [
                    {
                        headerName: "横向(%)",
                        field: "shrinkageHangDryTransverse",
                        slotName: "shrinkageHangDryTransverse",
    
                    },
                    {
                        headerName: "直向(%)",
                        field: "shrinkageHangDryStraight",
                        slotName: "shrinkageHangDryStraight",
    
                    },
                ]
            },
            {
                headerName: "缩水率(抛干)",
                key: "shrinkageFlatdry",
                children: [
                    {
                        headerName: "横向(%)",
                        field: "shrinkageThrowDryTransverse",
                        slotName: "shrinkageThrowDryTransverse",
    
                    },
                    {
                        headerName: "直向(%)",
                        field: "shrinkageThrowDryStraight",
                        slotName: "shrinkageThrowDryStraight",
    
                    },
                ]
            },
            {
                headerName: "缩水率(平干)",
                key: "shrinkageFlatdry",
                children: [
                    {
                        headerName: "横向(%)",
                        field: "shrinkageFlatDryTransverse",
                        slotName: "shrinkageFlatDryTransverse",
    
                    },
                    {
                        headerName: "直向(%)",
                        field: "shrinkageFlatDryStraight",
                        slotName: "shrinkageFlatDryStraight",
    
                    },
                ]
            },
            {
                headerName: "扭度(挂干)%",
                key: "torsionHangDry",
                field: "torsionHangDry",
                slotName: "torsionHangDry",
            },
            {
                headerName: "扭度(抛干)%",
                key: "torsionThrowDry",
                field: "torsionThrowDry",
                slotName: "torsionThrowDry",
            },
            {
                headerName: "扭度(平干)%",
                key: "torsionFlatDry",
                field: "torsionFlatDry",
                slotName: "torsionFlatDry",
            },
            {
                headerName: "洗后克重(挂干)%",
                key: "washWeightHangDry",
                field: "washWeightHangDry",
                slotName: "washWeightHangDry",
            },
            {
                headerName: "洗后克重(抛干)%",
                key: "washWeightThrowDry",
                field: "washWeightThrowDry",
                slotName: "washWeightThrowDry",
            },
            {
                headerName: "洗后克重(平干)%",
                key: "washWeightFlatDry",
                field: "washWeightFlatDry",
                slotName: "washWeightFlatDry",
            },
            {
                headerName: "要求门幅",
                key: "requireWidth",
                field: "requireWidth",
                slotName: "requireWidth",
            },
            {
                headerName: "有效门幅",
                key: "validWidth",
                field: "validWidth",
                slotName: "validWidth",
            },
            {
                headerName: "要求克重",
                key: "requireWeight",
                field: "requireWeight",
                slotName: "requireWeight",
            },
            {
                headerName: "实测克重",
                key: "measuredWeight",
                field: "measuredWeight",
                slotName: "measuredWeight",
            },
            {
                headerName: "顶破强力",
                key: "burstStrength",
                field: "burstStrength",
                slotName: "burstStrength",
            },
            {
                headerName: "胀破强力",
                key: "dilapidationStrength",
                field: "dilapidationStrength",
                slotName: "dilapidationStrength",
            },
            {
                headerName: "耐日晒色牢度",
                field: "SunColorFastness",
            },
            {
                headerName: "耐酚黄色牢度",
                key: "phenolYellowColorFastness",
                field: "phenolYellowColorFastness",
                slotName: "phenolYellowColorFastness",
            },
            {
                headerName: "PH值",
                key: "phValue",
                field: "phValue",
                slotName: "phValue",
            },
            {
                headerName: "甲醛",
                key: "formaldehyde",
                field: "formaldehyde",
                slotName: "formaldehyde",
            },
            {
                headerName: "纬斜",
                key: "latitudinalObliquity",
                field: "latitudinalObliquity",
                slotName: "latitudinalObliquity",
            },
            {
                headerName: "耐光、汗复合色牢度",
                key: "colourAndLightPerspiration",
                children: [
                    {
                        headerName: "酸",
                        field: "lightSweatColorFastnessSour",
                        slotName: "lightSweatColorFastnessSour",
    
                    },
                    {
                        headerName: "碱",
                        field: "lightSweatColorFastnessAlkali",
                        slotName: "lightSweatColorFastnessAlkali",
    
                    },
                ]
            },
            {
                headerName: "泡水",
                key: "soakWater",
                field: "soakWater",
                slotName: "soakWater",
            },
            {
                headerName: "纵密(CPI)",
                key: "verticalDensityCPI",
                field: "verticalDensityCPI",
                slotName: "verticalDensityCPI",
            },
            {
                headerName: "横密(WPI)",
                key: "transverseDensityCPI",
                field: "transverseDensityCPI",
                slotName: "transverseDensityCPI",
            },
            {
                headerName: "耐摩擦色牢度",
                key: "rubbingColourFastness",
                children: [
                    {
                        headerName: "干",
                        field: "frictionColorFastnessDry",
                        slotName: "frictionColorFastnessDry",
    
                    },
                    {
                        headerName: "湿(浅色)",
                        field: "frictionColorFastnessWetTint",
                        slotName: "frictionColorFastnessWetTint",
    
                    },
                    {
                        headerName: "湿(深色)",
                        field: "frictionColorFastnessWetDark",
                        slotName: "frictionColorFastnessWetDark",
    
                    },
                ]
            },
            {
                headerName: "耐皂洗色牢度",
                key: "soapWashColorFastness",
                field: "soapWashColorFastness",
                slotName: "soapWashColorFastness",
            },
            {
                headerName: "耐汗渍色牢度",
                key: "perspirationColourFastness",
                children: [
                    {
                        headerName: "酸",
                        field: "stainColorFastnessSour",
                        slotName: "stainColorFastnessSour",
    
                    },
                    {
                        headerName: "碱",
                        field: "stainColorFastnessAlkali",
                        slotName: "stainColorFastnessAlkali",
    
                    },
                ]
            },
            {
                headerName: "耐水色牢度",
                key: "waterColorFastness",
                field: "waterColorFastness",
                slotName: "waterColorFastness",
            },
            {
                headerName: "扛起球",
                key: "resistPill",
                field: "resistPill",
                slotName: "resistPill",
            },
            {
                headerName: "耐唾液色牢度",
                key: "salivaColorFastness",
                field: "salivaColorFastness",
                slotName: "salivaColorFastness",
            },
            {
                headerName: "备注",
                key: "remark",
                field: "remark",
                slotName: "remark",
            },
            {
                headerName: "用量",
                key: "consumption",
                field: "consumption",
                slotName: "consumption",
            },
            {
                headerName: "测试标准",
                key: "verifyStandard",
                field: "verifyStandard",
                slotName: "verifyStandard",
            },
            {
                headerName: "审核状态",
                field: "auditState",
                cellRenderer: {
                    template:`<div>已审核</div>`, 
                }
            },
           
            {
                headerName: "审核人",
                field: "auditPerson",
            },
            {
                headerName: "审核日期",
                field: "auditDate",
                width: 170,
            },
            {
                headerName: "创建人",
                field: "createName",
                width: 170,
            },
            {
                headerName: "创建时间",
                field: "createTime",
                width: 170,
            },
            {
                headerName: "修改人",
                field: "updateName",
                width: 170,
            },
            {
                headerName: "修改时间",
                field: "updateTime",
                width: 170,
            },
        ];
        let a = [{
            showRowGroup: 'hide_def',
            "headerName": "",
            "checkboxSelection": true,
            "headerCheckboxSelection": true,
            "pinned": "left",
            "width": 50,
            resizable: false,
            filter: false,
            sortable: false,
            minWidth: 50,
            maxWidth: 50,
            lockPosition: "left",
        }]
        cfsValue = a.concat(cfsValue);
        const total = ref(10); 
        const changePage = (val:any) => {
            pagination.page = val
            doRefresh();
        }
        const changeSize = (val:any) => {
            pagination.pageSize = val
            doRefresh();
        }

        const localeTextData :any = ref(localeText);
        emitter.on('changTestApprovedRows',() => {
            let idsArr = gridOption.value.getSelectedRows();
            emit('chang-auids',idsArr);
        });

        emitter.on('exportsTestApprovedRows',() => { 
            let selectList = gridOption.value.getSelectedRows();
            console.log(selectList);
            if (selectList.length === 0) {
                Message.error('请勾选需要导出的数据')
                return
            } else {
                //导出数据
                let nowRow = table.dataList.filter(function (o) {
                    return (gridOption.value.getSelectedRows().map((o: any) => { return o.id })).indexOf(o["id"]) !== -1;
                })
                assTable(cfsValue,nowRow,'缩水测试原始资料登记');
            }
        });
        return {
            pagination,
            table,
            localeTextData,
            changePage,
            changeSize,
            total,
            cfsValue,
            defaultColDef,
            gridReady,
        }
    } 
}
</script>
<style scoped>
.aInput{
  width: 270px;background: #fff;border: 1px solid #c9cdd3;
}
</style>